package com.first.teacher.controller;

import com.first.common.pojo.EduCourse;
import com.first.common.vo.Result;
import com.first.teacher.service.ShouCangService;
import com.first.teacher.vo.ShouCangVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @program: finrsteducation-parent
 * @description:
 * @author: 张玉森
 * @create: 2023-06-05 20:02
 **/
@RestController
@RequestMapping("/core/shoucangCourse")
@Api(tags = "成员收藏类接口")
public class ShouCangCourseController {
    @Autowired
    private ShouCangService shouCangService;
    @PostMapping("findFavoriteCourse")
    @ApiOperation("渲染页面是否已经收藏")
    private Result findFavoriteCourse(@RequestBody ShouCangVo shouCangVo){
        Long number= shouCangService.selectFavoriteCourse(shouCangVo);
        Map<String,Integer> map=new HashMap<>();
        if (number==0){
            map.put("status",0);
        }else {
            map.put("status",1);
        }
        return Result.success(map);
    }
    @PostMapping("deleteFavoriteCourse")
    @ApiOperation("取消收藏")
    public Result deleteFavoriteCourse(@RequestBody ShouCangVo shouCangVo){
        Integer delete= shouCangService.deleteFavoriteCourse(shouCangVo);
        if (delete>0){
            return Result.success(delete);
        }else {
            return Result.fail("取消收藏失败");
        }
    }
    @PostMapping("addFavoritescourse")
    @ApiOperation("收藏课程")
    public Result addFavoritescourse(@RequestBody ShouCangVo shouCangVo) {
        Integer add = shouCangService.addFavoritescourse(shouCangVo);
        if (add > 0) {
            return Result.success(add);
        } else {
            return Result.fail("收藏失败");
        }
    }

    @PostMapping("/findFavoriteCourseById/{HuiYuanId}")
    @ApiOperation("我的收藏")
    private Result findFavoriteCourseById(@PathVariable String HuiYuanId){
        List<EduCourse> favoriteCourseById = shouCangService.findFavoriteCourseById(HuiYuanId);
        return Result.success(favoriteCourseById);
    }


}